(display "\n========================================\n")
(define (start-segment AB)
    (car AB))

(define (end-segment AB)
    (cdr AB))

(define (make-segment A B)
    (cons A B))

(define (make-point x y)
    (cons x y))

(define (x-point p)
    (car p))

(define (y-point p)
    (cdr p))

(define (print-point p)
    (display "(")
    (display (x-point p))
    (display ",")
    (display (y-point p))
    (display ")\n"))

; (print-point (cons 3 4))

(define (midpoint-segment AB)
    (define (average a b)
        (/ (+ a b) 2))
    (define A (start-segment AB))
    (define B (end-segment AB))
    (define x (average (x-point A) (x-point B)))
    (define y (average (y-point A) (y-point B)))
    (cons x y))

(define (midpoint-segment AB)
    (define (average a b)
        (/ (+ a b) 2))
    (let ((A (start-segment AB))
          (B (end-segment AB)))
         (make-point (average (x-point A) (x-point B))
                     (average (y-point A) (y-point B)))))

(define AB (make-segment (make-point 2 2) (make-point 4 4)))
(print-point (start-segment AB))
(print-point (end-segment AB))
(print-point (midpoint-segment AB))
(display "\n========================================\n")
